package com.chixing.day15_map_file.work;

import java.io.*;

public class FileCopy {
    public static void main(String[] args) {
        OutputStream os = null;
        InputStream is = null;
        try {
            os = new FileOutputStream("e://test2/hello.txt");
            is = new FileInputStream("f://test1/hello.txt");

            byte[] data = new byte[1024];
            int len;
            while (true){
                try {
                    if (!((len = is.read(data))!=-1)) break;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                try {
                    os.write(data,0,len);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                os.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                is.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
